<?php

use yii\helpers\Html;
use kartik\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\business\models\BusinessVaccineSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '仔猪疫苗';
$this->params['breadcrumbs'][] = $this->title;
?>


<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
              <?= Html::a('返回','javascript:history.back(-1)'); ?>  <?= Html::encode($this->title) ?>
        </header>
        <div class="panel-body">
            <div class="adv-table editable-table ">
 


<div class="business-vaccine-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('添加仔猪疫苗', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider'=>$dataProvider,
        'filterModel'=>$searchModel,
        'showPageSummary'=>true,
        'pjax'=>false,
        'striped'=>true,
        'hover'=>true,
        'panel'=>['type'=>'primary', 'heading'=>'仔猪疫苗'],
        'containerOptions'=>['style'=>'overflow: auto'], // only set when $responsive = false
        'headerRowOptions'=>['class'=>'kartik-sheet-style'],
        'filterRowOptions'=>['class'=>'kartik-sheet-style'],
        'columns'=>[

            [
                'attribute'=>'no',
                'label' => '仔猪编号',
                'format' => 'raw',
//                'value' => function($model){
//                    return $model->pig?Html::a($model->pig->no,\yii\helpers\Url::to(['/business/pig/view','id'=>$model->pig->id])):'(未设置)';
//                },
                'value' => 'pig.no',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],
            [
                'attribute'=>'vaccinename',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],
            [
                'attribute'=>'remark',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],

            [
                'attribute'=>'date',
                'label' => '疫苗日期',
                'filterType'=>GridView::FILTER_DATE,
                'class' => '\kartik\grid\DataColumn',
                'filterWidgetOptions'=>[
                    'pluginOptions'=>[
                        'format' => 'yyyy-mm-dd',
                        'autoclean' => true,
                    ],
                ],
                'value'=>
                    function($model){
                        return  date('Y-m-d',$model->date);   //主要通过此种方式实现
                    },
                'width'=>'100px',
            ],
            [
                'class' => '\kartik\grid\CheckboxColumn'
            ],
            [
                'class' => '\kartik\grid\ActionColumn',
                'deleteOptions' => ['label' => '<i class="glyphicon glyphicon-remove"></i>']
            ],
        ],
        'toolbar'=> [
            [
                'content' => Html::button('<i class="glyphicon glyphicon-delete">批量添加疫苗</i>', ['type'=>'button', 'title'=>'批量添加疫苗', 'class'=>'btn btn-success', 'id'=>'setvaccine']),
            ],
            [
                'content' => Html::button('<i class="glyphicon glyphicon-delete">批量更新疫苗</i>', ['type'=>'button', 'title'=>'批量更新疫苗', 'class'=>'btn btn-primary', 'id'=>'batchupdate'])
            ],
            [
                'content' => Html::button('<i class="glyphicon glyphicon-delete">批量删除疫苗</i>', ['type'=>'button', 'title'=>'批量删除疫苗', 'class'=>'btn btn-danger', 'id'=>'batchdelete'])
            ],
            '{export}',
            '{toggleData}',
        ],
        'bordered'=>true,
        'condensed'=>true,
    ]);
    ?>




    <!--设置疫苗-->
    <div id="setvaccine-modal" class="fade modal in" role="dialog">
        <div class="modal-dialog ">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">批量设置仔猪信息</h4>
                </div>
                <div class="modal-body">
                    <form method="post" action="/business/vaccine/setvaccine">
                        <div class="form-group">
                            <label for="formatno">仔猪编号前缀</label>
                            <input type="text" name="formatno" class="form-control" id="formatno" placeholder="仔猪编号前缀">
                        </div>

                        <div class="form-group">
                            <label for="basenum">范围起始编码</label>
                            <input type="number" name="basenum" class="form-control" id="basenum" placeholder="起始编码">
                        </div>

                        <div class="form-group">
                            <label for="endnum">范围截止编码</label>
                            <input type="number" name="endnum" class="form-control" id="endnum" placeholder="截止编码">
                        </div>

                        <div class="form-group">
                            <label for="date">疫苗时间</label>
                            <input type="date" name="date" class="form-control" id="date" placeholder="疫苗时间">
                        </div>
                        <div class="form-group">
                            <label for="remark">疫苗名称</label>
                            <select name="vaccineid" id="" class="form-control">
                                <?php foreach ($vaccset as $key => $row){ ?>
                                    <option value="<?=$row['id']?>"><?=$row['vaccinename']?></option>
                                <?php } ?>
                            </select>
<!--                            <input type="text" name="vaccinename" class="form-control" id="vaccinename" placeholder="疫苗名称">-->
                        </div>

                        <div class="form-group">
                            <label for="remark">备注</label>
                            <input type="text" name="remark" class="form-control" id="remark" placeholder="备注">
                        </div>
                        <input type="hidden" name="_csrf" value="<?=Yii::$app->request->csrfToken; ?>">
                        <button type="submit" class="btn btn-success">确认</button>
                    </form>
                </div>
                <div class="modal-footer">
                    <a href="#" class="btn btn-primary" data-dismiss="modal">关闭</a>
                </div>
            </div>
        </div>
    </div>

    
    
    <!--批量更改疫苗-->
    <div id="batchupdate-modal" class="fade modal in" role="dialog">
        <div class="modal-dialog ">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">批量设置仔猪信息</h4>
                </div>
                <div class="modal-body">
                    正在加载。。。。
                </div>
                <div class="modal-footer">
                    <a href="#" class="btn btn-primary" data-dismiss="modal">关闭</a>
                </div>
            </div>
        </div>
    </div>


</div>
</div>
</div>
</section>
</section>


<script>
    <?php $this->beginBlock('js_end') ?>

    $(document).ready(function(){
        //批量设置时间
        $('#setvaccine').click(function () {
            $('#setvaccine-modal').modal();
        })

        //批量设置时间
        $('#batchupdate').click(function () {
            console.log("点击有效");
            var keys = jqchk();
            if(keys.length == 0){
                alert('请选择要更改的疫苗');
                return false;
            }
            $('#batchupdate-modal').modal();

            $.get('batchupdate',{'ids':keys},function(html){
                $('#batchupdate-modal .modal-body').html(html);
            });

        });


        $('#batchdelete').click(function () {
            var keys = jqchk();
            if(keys.length == 0){
                alert('请选择要删除的疫苗');
                return false;
            }

            $.post('muti-delete',{'ids':keys},function(html){
                alert(html.msg);
                if(html.status == 0){
                    location.href="index";
                }else{
                    window.location.reload();
                }
            },'json');

        })


        function jqchk() { //jquery获取复选框值=
            var chk_value = [];
            $('input[name="selection[]"]:checked').each(function () {
                chk_value.push($(this).val());
            });
            return chk_value;
        }
    })

    <?php $this->endBlock(); ?>
    <?php $this->registerJs($this->blocks['js_end'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
</script>




